<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>用户管理</title>
    <c:set var="contextPath" value="${pageContext.request.contextPath}" scope="request"/>
	<link rel="stylesheet" href="${contextPath}/static-resources/css/index.css"/>
	<script src="${contextPath}/static-resources/jquery-1.12.1.js"></script>
	<script src="${contextPath}/static-resources/js/index.js"></script>
	
	<link rel="stylesheet" type="text/css" href="${contextPath}/static-resources/themes/material/easyui.css">
	<link rel="stylesheet" type="text/css" href="${contextPath}/static-resources/themes/icon.css">
	<script type="text/javascript" src="${contextPath}/static-resources/jquery.min.js"></script>
	<script type="text/javascript" src="${contextPath}/static-resources/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#userTable').datagrid({
				onDblClickRow: function(index,row){
					console.log(row.logo);
					$('#img').prop('src', row.avatar);
					$('#showImgWin').window('open');
				}
			});
		})
		
		function openAddUserWin(){
			// $('#addUserWin').window('open');
		}
		
		function sexFormatter(value){
			if (!value) {
				return "";
			}
			if(value=='f'){
				return '女';
			}else if (value=='m') {
				return '男';
			}
			return value;
		}

		function addImage() {
			console.log('asdfsadf');			
			var productionId = $('#production').combobox('getValue');
			console.log(productionId);
			console.log(productionId);
			var description = $('#description').textbox('getValue');
			console.log(description);
			var fileInputId = $('#url').next().find('input[type="file"]').attr("id");
			var file = document.getElementById(fileInputId).files[0];
			
			if (!productionId) {
				showInfo("所属作品不能为空");
				return;
			}
			if (!file) {
				showInfo("作品图片不能为空");
				return;
			}
			
			var reader = new FileReader();
			reader.onload = function(e) {
				var base64stream = this.result;
				var dataObj = new Object();
				dataObj.fileName = file.name;
				dataObj.base64stream = base64stream;
				dataObj.productionId = productionId;
				dataObj.description = description;
				openMask();
				$.ajax({
					type : "POST",
					url : '${contextPath}/image/add.do',
					enctype : 'multipart/form-data',
					data : dataObj,
					success : function(data) {
						if (data.status) {
							$('#addUserWin').window('close');
							$('#userTable').datagrid('reload');
						} else {
							showError(data.message);
						}
						closeMask();
					},
					error : function() {
						showError('系统异常');
						closeMask();
					}
				});
			};
			reader.readAsDataURL(file);
		}
		
	</script>
</head>
<body style="height: 100%;">
	<div class="find_nav">
	    <div class="find_nav_left">
	        <div class="find_nav_list">
	            <ul>
	                <li><a href="javascript:void(0)" url="${contextPath}/exhibition/index.do">展览</a></li>
	                <li><a href="javascript:void(0)" url="${contextPath}/exhibitionHome/index.do">展厅</a></li>
	                <li><a href="javascript:void(0)" url="${contextPath}/production/index.do">作品</a></li>
	                <li><a href="javascript:void(0)" url="${contextPath}/image/index.do">图片</a></li>
	                <li class="selected"><a href="javascript:void(0)" url="${contextPath}/user/index.do">用户</a></li>
	                <li><a href="javascript:void(0)" url="${contextPath}/banner/index.do">banner</a></li>
	                <li class="sideline"></li>
	            </ul>
	        </div>
	    </div>
	</div>
	<div id="content" style="width: 100%; position: absolute;top: 45px;">
		<table id="userTable" class="easyui-datagrid" title="作品" style="width:100%;height:100%;"
			data-options="rownumbers:true, singleSelect:true, url:'${contextPath}/user/listJson.do', method:'get',
			toolbar:'#userTableTB' " >
			<thead>
				<tr>
					<th data-options="field:'ck', checkbox:true"></th>
					<th data-options="field:'id', width:'10%'">id</th>
					<th data-options="field:'userName', width:'10%'">昵称</th>
					<th data-options="field:'name', width:'10%'" >真实姓名</th>
					<th data-options="field:'mobile', width:'10%'">电话</th>
					<th data-options="field:'sex', width:'5%'">性别</th>
					<th data-options="field:'qq', width:'10%'">qq</th>
					<th data-options="field:'verify', width:'10%'">是否认证</th>
					<th data-options="field:'productionSize', width:'5%'">作品数量</th>
					<th data-options="field:'createTime', width:'10%'" formatter = "dateTimeFormatter">注册日期</th>
					<th data-options="field:'lastLoginTime', width:'10%'" formatter = "dateTimeFormatter">注册日期</th>
					<th data-options="field:'avatar', width:'15%'">头像</th>
				</tr>
			</thead>
		</table>
		
		<div id="userTableTB">
			<a href="#" class="easyui-linkbutton" iconCls="icon-sum" plain="true" onclick="$('#userTable').datagrid('reload')">查询所有</a>
         	<span class="datagrid-btn-separator" style="vertical-align: middle;display:inline-block;float:none"></span>
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="openAddUserWin()">添加</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="">编辑</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeImage()">删除</a>
		</div>
		
		<!-- ##############下面是添加作品图片相关的窗体############## -->
		<div id="addUserWin" class="easyui-window" title="添加作品图片" data-options="iconCls:'icon-add', collapsible:'false', modal:'true', closed:true, footer:'#addUserWinFooter'" style="width:450px; height:350px; padding:10px;" >
			<div style="margin-bottom:5px">
				<input class="easyui-textbox" id="name" data-options="label: '真实姓名：', labelPosition:'before'" style="width: 100%;"/>
			</div>
			<div style="margin-bottom:5px">
				<input class="easyui-textbox" id="mobile" data-options="label: '手机号：', labelPosition:'before'" style="width: 100%;"/>
			</div>
			<div style="margin-bottom:5px">
				<div style="width: 84px; height: 100%;float: left; vertical-align: middle;">性别：</div>
				<input class="easyui-switchbutton" id="sex" data-options="onText:'男', offText:'女'" >
			</div>
		</div>
		
		<div id="addUserWinFooter" class="windowFooter">
			<a href="#" class="easyui-linkbutton" icon="icon-ok" onclick="addImage()">确定</a>  
            <a href="#" class="easyui-linkbutton" icon="icon-cancel" onclick="$('#addUserWin').window('close')">取消</a>  
		</div>
		
		<!-- ##############显示图片的窗口############## -->
		<div id="showImgWin" class="easyui-window" title="图片预览" data-options="iconCls:'icon-add', collapsible:'false', modal:'true', closed:true, footer:'#showImgWinFooter'" style="width:500px; height:500px; padding:10px;" >
			<div style="width: 100%; height: 100%;">
				<img id="img" alt="" src="" />
			</div>
		</div>
		<div id="showImgWinFooter" class="windowFooter">
            <a href="#" class="easyui-linkbutton" icon="icon-cancel" onclick="$('#showImgWin').window('close')">取消</a>  
		</div>
		
	</div>
</body>


</html>